package com.dqyt.quart;

import com.alibaba.fastjson.JSON;
import com.dqyt.khjc.bean.User;
import com.dqyt.khjc.mapper.UserMapper;
import com.dqyt.khjc.sms.SMSConfig;
import com.dqyt.khjc.sms.SMSParm;
import com.dqyt.khjc.sms.SMSTool;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 批准任务 定时发送短信
 */
@Slf4j
public class PzrwTask implements Job {


    @Autowired
    private UserMapper userMapper;

    /**
     * @author jinhaoxun
     * @description 重写任务内容
     * @param jobExecutionContext 设置的key
     * @throws
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
       // System.out.println(userMapper);
        try {
            List<User> data = new ArrayList<>();
            List<User>  alldata = userMapper.getUserListJc();
            for(User user:alldata){
                String jsStr = user.getRole();
                String [] jsArray =jsStr.split(",");
                List<String> listB= Arrays.asList(jsArray);
                if(listB.contains("4")){
                    data.add(user);
                }
            }
            for(User mUser:data){
                String mphon =mUser.getPhone();
                if(null !=mphon && !"".equals(mphon)){
                    SMSParm mSMSParm = new SMSParm();
                    mSMSParm.TemplateID = SMSConfig.DPZBG_SMS; // 模板ID
                    String[] a = { "+86" + mphon }; // 发送对象电话号码
                    mSMSParm.PhoneNumberSet = a;
                    SendSmsResponse smsRet = SMSTool.sendSMS(JSON.toJSONString(mSMSParm));
                    if (SMSTool.isSendSMSOK(smsRet)) {
                        System.out.println("发送成功");
                    }
                }
            }
        } catch (Exception e) {
            //log.info("Quartz执行失败");
        }
    }
}